<template>
  <div>
    <router-link :to="'/comment/AddComment?fid='+this.fid"><el-button>添加评论</el-button></router-link>
    <el-table
      :data="CommentList"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="title"
        label="标题">
      </el-table-column>

      <el-table-column
        prop="createDate"
        label="时间">
      </el-table-column>
      <el-table-column
        label="操作" v-if="role==2">
        <template slot-scope="scope">
          <el-button @click="deleteById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <router-view/>
  </div>
</template>

<script>
    export default {
        name: "CommentList",
      data(){
          return {
            CommentList:[],
            fid:"",
            role:sessionStorage.getItem("role")
          }
      },
      created(){
          this.fid=this.$route.query.fid;
        this.selectAll();
      },
      methods: {
        deleteById(id){
          this.$confirm("是否确认删除","删除提示").then(()=>{
            this.axios.delete("/comment/del/"+id).then((resp)=>{
              this.$message.success("删除成功！");
              this.selectAll();
            });
          });
        },
        selectAll(){
          this.axios.get("/comment/selectByFid?fid="+this.$route.query.fid).then((resp)=>{
            this.CommentList=resp.data;
          });
        }
      }
    }
</script>

<style scoped>

</style>
